package leetcode.editor.cn;
//[62]不同路径
public class UniquePaths62{
public static void main(String[] args) {
   Solution solution = new UniquePaths62().new Solution();
   
}

  //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int uniquePaths(int m, int n) {
        if (m<1||n<1) return 0;
        int x = n;
        int y = m;
//        int[][] res = new int[x][y];
        int[][] res = new int[x+1][y+1];//省略了判断 for 判断 0 越界的位置。

        //问题，等价于 从00--》x-1,y-1;
        //不需要初始化 上面的 0 ;
        //从00--》x-1,y-1;
        res[1][1] = 1;
         for (int i = 1; i <= x; i++) {
            for (int j = 1; j <= y; j++) {
                if (i==1 && j==1){//防止 x=0 y=0 2列，把初始值给干掉。
                    res[i][j]=1;
                }else {
                    res[i][j] = res[i-1][j] + res[i][j-1];
                }
            }
        }
        return res[x][y];

         //官方解答：
 /*       class Solution {
            public int uniquePaths(int m, int n) {
                int[][] f = new int[m][n];
                for (int i = 0; i < m; ++i) {
                    f[i][0] = 1;
                }
                for (int j = 0; j < n; ++j) {
                    f[0][j] = 1;
                }
                for (int i = 1; i < m; ++i) {
                    for (int j = 1; j < n; ++j) {
                        f[i][j] = f[i - 1][j] + f[i][j - 1];
                    }
                }
                return f[m - 1][n - 1];
            }
        }
*/
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}